home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Mac OS USB DDK_v1.0.1 / Examples / PrinterClassDriver / MissingLibraryRoutines.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-03  |  4.1 KB  |  117 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MissingLibraryRoutines.c
  3.  
  4.     Contains:    Implementation of routines missing from InterfaceLib.
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Written by:    Quinn "The Eskimo!"
  9.  
  10.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  11.  
  12.     File Ownership:
  13.  
  14.         DRI:                Craig Keithley
  15.  
  16.         Other Contact:        xxx put other contact here xxx
  17.  
  18.         Technology:            USB Drivers
  19.  
  20.     Writers:
  21.  
  22.         (CJK)    Craig Keithley
  23.  
  24.     Change History (most recent first):
  25.  
  26.       <USB3>     5/28/98    CJK        change file creater to 'MPS '
  27.       <USB2>     5/26/98    CJK        add prototypes for the unit table functions
  28.     You may incorporate this sample code into your applications without
  29.     restriction, though the sample code has been provided "AS IS" and the
  30.     responsibility for its operation is 100% yours.  However, what you are
  31.     not permitted to do is to redistribute the source as "DSC Sample Code"
  32.     after having made changes. If you're going to re-distribute the source,
  33.     we require that you make it clear in the source that the code was
  34.     descended from Apple Sample Code, but that you've made changes.
  35. */
  36.  
  37. #include <Types.h>
  38. #ifndef __MIXEDMODE__
  39. #include <mixedmode.h>
  40. #endif
  41. #ifndef __DEVICES__
  42. #include <devices.h>
  43. #endif
  44.  
  45. // This file contains implementations of various Mac OS API routines
  46. // that were never rolled in to InterfaceLib.  As a result, these
  47. // routines can be called from classic 68K clients, but not from
  48. // CFM-68K or CFM-PPC clients.
  49.  
  50. extern pascal SInt16 LMGetUnitTableEntryCount(void);
  51. extern pascal void LMSetUnitTableEntryCount(SInt16 value);
  52.  
  53. extern pascal SInt16 LMGetUnitTableEntryCount(void)
  54.     // Get the value from low memory directly.
  55. {
  56.     return *((SInt16 *) 0x01d2);
  57. }
  58.  
  59. extern pascal void LMSetUnitTableEntryCount(SInt16 value)
  60.     // Put the value into low memory directly.
  61. {
  62.     *((SInt16 *) 0x01d2) = value;
  63. }
  64.  
  65. // DriverInstallReserveMem is a bit trickier to implement that the
  66. // previous two routines.  Basically we have get the address of the
  67. // _DriverInstall ($A03D) trap and then call it using
  68. // CallOSTrapUniversalProc.  There are a number of important things
  69. // to note here:
  70. //   a) We can just get the trap address and treat it as a UPP.
  71. //      The trap tables are defined to contain UPPs, either pointers
  72. //      to real 68K code, or pointers to a routine descriptor (if
  73. //      the trap is native or fat).
  74. //   b) We must use CallOSTrapUniversalProc, not CallUniversalProc.
  75. //      CallOSTrapUniversalProc automatically does a number of things 
  76. //      that are very critical for call OS traps.  See "IM:PowerPC
  77. //      System Software", p2-42 for a full description.
  78. //   c) When calling OS traps from PPC, it's important to get the
  79. //      ProcInfo right.  Specifically, all OS traps assume an
  80. //      implicit parameter of D1 as the first parameter.  After
  81. //      that, the parameters should be defined in the order that
  82. //      they are declared in the prototype.  If you fail to get
  83. //      the order right, or to put D1 first, your code will work,
  84. //      up until it encounters someone who has patched the OS trap
  85. //      with a native or fat patch.  Then strange things will happen,
  86. //      and you'll spend hours in MacsBug trying to figure it out.
  87.  
  88. // The trap number and ProcInfo description for DriverInstallReserveMem.
  89.  
  90. enum {
  91.     _DriverInstallReserveMem = 0x0A43D
  92. };
  93.  
  94. enum {
  95.     uppDriverInstallProcInfo = kRegisterBased
  96.         | REGISTER_RESULT_LOCATION(kRegisterD0)
  97.         | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  98.         | REGISTER_ROUTINE_PARAMETER(1, kRegisterD1, SIZE_CODE(sizeof(short)))
  99.         | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(DRVRHeaderPtr)))
  100.         | REGISTER_ROUTINE_PARAMETER(3, kRegisterD0, SIZE_CODE(sizeof(short)))
  101. };
  102.  
  103. extern pascal OSErr DriverInstallReserveMem(DRVRHeaderPtr drvrPtr, short refNum)
  104. {
  105.     UniversalProcPtr trapAddress;
  106.     
  107.     // Check that I've got the ProcInfo correct.
  108.     if (false) {
  109.         if ( uppDriverInstallProcInfo != 0x00533022) {
  110.             DebugStr("\pDriverInstallReserveMem: uppDriverInstallProcInfo is not what it should be.");
  111.         }
  112.     }
  113.     
  114.     trapAddress = (UniversalProcPtr) GetOSTrapAddress(_DriverInstallReserveMem);
  115.     return CallOSTrapUniversalProc(trapAddress, uppDriverInstallProcInfo, _DriverInstallReserveMem, drvrPtr, refNum);
  116. }
  117.